package com.jiangwz.sort;

/**冒泡排序
 * @author jiangwz
 * @create 2021/3/17.
 */
public class BubbleSort extends BaseSort{


    public static void main(String[] args){
        int[] arr = new int[]{9,1,3,2,5,6,8,7,4};
        sort(arr);
    }

    public static void sort(int[] arr){
        print(arr);
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length-1; j++) {
                if (arr[j] > arr[j+1]) {
                    swap(arr, j, j+1);
                    print(arr);
                }
            }
        }

        print(arr);
    }

    private static void sortN(int[] arr, int i) {
        for (int j = 0; j < i-1; j++) {
            if (arr[j] > arr[j+1]) {
                swap(arr, j, j+1);
            }
        }
    }


}
